package cn.lyjuan.first.netty._4_netty_serialize.msg.reader.impl;

import cn.lyjuan.base.util.HexUtils;
import cn.lyjuan.first.netty._4_netty_serialize.cst.MessageConst;
import cn.lyjuan.first.netty._4_netty_serialize.msg.codec.MessageCodec;
import cn.lyjuan.first.netty._4_netty_serialize.msg.reader.IReader;
import io.netty.buffer.ByteBuf;

public class MsgReaderImpl extends AbstractReader
{
    @Override
    public String head()
    {
        return MessageConst.HEAD_MSG;
    }

    @Override
    public int dataLength()
    {
        return 0;
    }

    @Override
    public String read(ByteBuf buf)
    {
        return readToFoot(buf);


        /*byte[] b = new byte[1];// 一次仅读取一个字节
        String tmp = null;
        StringBuilder sb = new StringBuilder();
        // 读取到结尾
        while (buf.isReadable())
        {
            buf.readBytes(b);
            tmp = HexUtils.toHex(b);
            sb.append(tmp);

            if (sb.indexOf(MessageConst.FOOT) > -1)
            {
                sb.delete(sb.length() - MessageConst.LEN_FOOT, sb.length());// 去掉尾部
                buf.readerIndex(buf.readerIndex() - MessageConst.LEN_FOOT);// 恢复尾部位置

                break;
            }
        }

        return sb.toString();*/
    }
}
